#ifndef __TOYM__NET__POLLER_H__
#define __TOYM__NET__POLLER_H__

#include <vector>
#include <unordered_map>
#include "Base/noncopyable.h"

// 前置声明
struct pollfd;

namespace toym
{
namespace net
{

class Channel;

class Poller: noncopyable {
public:
    Poller();
    ~Poller();
    int poll();
    void updateChannel(Channel& channel);
    void removeChannel(Channel& channel);
    std::vector<Channel*> getActiveChannels(int nActive);
    void handleEvents(std::vector<Channel*>& activeChannels);
private:
    std::vector<struct pollfd> m_pfds;
    std::unordered_map<int, Channel*> channelMap;  // map from fd to channel

    static int intervalMicroseconds;
};

} // namespace net

} // namespace toym


#endif //__TOYM__NET__POLLER_H__